package business.application;

import java.io.IOException;

import business.search_eng.Document;

import org.kth.dks.JDHT;
import org.kth.dks.dks_exceptions.DKSIdentifierAlreadyTaken;
import org.kth.dks.dks_exceptions.DKSRefNoResponse;
import org.kth.dks.dks_exceptions.DKSTooManyRestartJoins;

public class Instance {
	public static void main(String[] arg) {
		int port = 44000;
		JDHT DHTNode = null;
		
		try {
			if (arg.length>=1)  {
				System.out.println("Joining "+arg[0]);
				DHTNode = new JDHT(port,arg[0]);
				System.out.println( ((JDHT)DHTNode).getReference() );
			} else {
				System.out.println("Creating JDHT");
				DHTNode = new JDHT(port);
				System.out.println( ((JDHT)DHTNode).getReference() );
			}
		
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (DKSTooManyRestartJoins e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (DKSIdentifierAlreadyTaken e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (DKSRefNoResponse e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			Document aDocument = (Document) DHTNode.get("22");
			System.out.println(aDocument.showData());
		}
	}
	
	public static void get() {
	}
	
	public static void add() {
		
	}
}
